﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RMS.Utils.MVP;
using RMS.Web.Shell.View;
using RMS.DataAccess.Entities;
using RMS.DataAccess.Repositories;

namespace RMS.Web.Shell.Presenter
{
    public class BookingRadiologyPresenter : Presenter<IBookingRadiologyView>, IView
    {
        RadiologyRequestRepository _radiologyRequestRepository;
        RadiologyTypeRepository _radiologyTypeRepository;
        PatientsRepository _patientsRepository;

        public BookingRadiologyPresenter(RadiologyRequestRepository radiologyRequestRepository,
        RadiologyTypeRepository radiologyTypeRepository, PatientsRepository patientsRepository)
        {
            _radiologyRequestRepository = radiologyRequestRepository;
            _radiologyTypeRepository = radiologyTypeRepository;
            _patientsRepository = patientsRepository;
        }

        public int insertBookingRadiology(RadiologyRequest radiologyRequest)
        {
            return _radiologyRequestRepository.Insert(radiologyRequest);
        }
        public bool UpdateRadiologyRequest(RadiologyRequest RadiologyRequest)
        {
            _radiologyRequestRepository.Update(RadiologyRequest);
            return true;
        }
        public RadiologyRequest GetBookedRadiology(int RequestId)
        {
            return _radiologyRequestRepository.Find(item => { item.RequestId = RequestId; }).Single(); ;
        }
        public IEnumerable<RadiologyType> GetRadiologyTypes()
        {
            return _radiologyTypeRepository.FindAll();
        }
        public int GetPetiontID(string patientName)
        {
            string[] names = patientName.Split(' ');
            return (_patientsRepository.Find(item =>
                    {
                        item.FirstName = names[0];
                        if (names.Count() > 1)
                            item.FamilyName = names[1];
                    }).Single()).PatientID;

        }
    }
}
